package com.meilingcloud.activiti.instener;

import com.meilingcloud.activiti.domain.ActWfStock;
import com.meilingcloud.activiti.service.IActWfStockService;
import com.meilingcloud.common.utils.spring.SpringUtils;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.Expression;

public class StockEndStateListener implements ExecutionListener {

    // 字段注入
    private Expression state;

    @Override
    public void notify(DelegateExecution execution) {
        ActWfStock actWfStock = new ActWfStock();
        actWfStock.setStockId(execution.getProcessInstanceBusinessKey());
        actWfStock.setInstanceId(execution.getProcessInstanceId());
        actWfStock.setStockState(state.getValue(execution).toString());

        SpringUtils.getBean(IActWfStockService.class).completeStock(actWfStock);
    }
}
